﻿using System;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;

namespace UniRx.Examples
{
	// Token: 0x020001F3 RID: 499
	public class Sample13_ToDoApp : MonoBehaviour
	{
		// Token: 0x06000A73 RID: 2675 RVA: 0x00037F0C File Offset: 0x0003630C
		private void Start()
		{
			IObservable<string>[] array = new IObservable<string>[2];
			array[0] = from _ in this.AddButton.OnClickAsObservable()
			select this.ToDoInput.text;
			array[1] = from _ in this.ToDoInput.OnEndEditAsObservable()
			where Input.GetKeyDown(KeyCode.Return)
			select _;
			IObservable<string> source = Observable.Merge<string>(array);
			(from x in source
			where x != string.Empty
			select x).Subscribe(delegate(string x)
			{
				this.ToDoInput.text = string.Empty;
				GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.SampleItemPrefab);
				(gameObject.GetComponentInChildren(typeof(Text)) as Text).text = x;
				this.toDos.Add(gameObject);
			});
			this.toDos.ObserveCountChanged(false).Subscribe(delegate(int x)
			{
				this.Title.text = "TODO App, ItemCount:" + x;
			});
			this.toDos.ObserveAdd().Subscribe(delegate(CollectionAddEvent<GameObject> x)
			{
				x.Value.transform.SetParent(this.TodoList.transform, false);
			});
			this.toDos.ObserveRemove().Subscribe(delegate(CollectionRemoveEvent<GameObject> x)
			{
				UnityEngine.Object.Destroy(x.Value);
			});
			this.ClearButton.OnClickAsObservable().Subscribe(delegate(Unit _)
			{
				GameObject[] array2 = (from x in this.toDos
				where x.GetComponent<Toggle>().isOn
				select x).ToArray<GameObject>();
				foreach (GameObject item in array2)
				{
					this.toDos.Remove(item);
				}
			});
		}

		// Token: 0x040006D7 RID: 1751
		public Text Title;

		// Token: 0x040006D8 RID: 1752
		public InputField ToDoInput;

		// Token: 0x040006D9 RID: 1753
		public Button AddButton;

		// Token: 0x040006DA RID: 1754
		public Button ClearButton;

		// Token: 0x040006DB RID: 1755
		public GameObject TodoList;

		// Token: 0x040006DC RID: 1756
		public GameObject SampleItemPrefab;

		// Token: 0x040006DD RID: 1757
		private ReactiveCollection<GameObject> toDos = new ReactiveCollection<GameObject>();
	}
}
